#include "stdafx.h"

#include "Sandbox.h"

#ifdef _DEBUG

#include "StickyTweetsAppXP.h"

VOID Sandbox::PrintRssDate()
{
  CTime thisPubDate(2009, 6, 14, 0, 0, 0);

  StickyTweetsAppXP& app = StickyTweetsAppXP::GetInstance();
    
  CString response;  
  StickyTweetsStatus status = app.GetWebResponse(L"stickytweets.codeplex.com", L"/Project/ProjectRss.aspx?ProjectRSSFeed=codeplex%3a%2f%2frelease%2fstickytweets", NULL, NULL, response, TRUE);
  if (status == StatusStOk)
  {
    INT startIdx = response.Find(L"<pubDate>") + 9;
    INT endIdx = response.Find(L"</pubDate>", startIdx);
    CString pubDate = response.Mid(startIdx, endIdx - startIdx);
    CTime pubTime = app.ParseDate(pubDate);
    ATLTRACE2(L"RSS pub date: %d-%d-%d\n", pubTime.GetYear(), pubTime.GetMonth(), pubTime.GetDay());
    if (pubTime > thisPubDate)
      ATLTRACE2(L"  New version of StickyTweets!\n");
    else
      ATLTRACE2(L"  That release must be me\n");
  }
}

VOID Sandbox::PrintVersion()
{
  TCHAR exePath[MAX_PATH];
  GetModuleFileName(NULL, exePath, MAX_PATH);
  INT exeIdx = CString(exePath).ReverseFind(L'\\') + 1;

  DWORD hVersion;
  DWORD size = GetFileVersionInfoSize(&exePath[exeIdx], &hVersion);

  TCHAR* pVersionInfo = new TCHAR[size];
  GetFileVersionInfo(&exePath[exeIdx], hVersion, size, pVersionInfo);

  VS_FIXEDFILEINFO* pFileInfo(NULL);
  UINT bufLen;
  VerQueryValue(pVersionInfo, L"\\", (LPVOID*)&pFileInfo, (PUINT)&bufLen);

  WORD major = HIWORD(pFileInfo->dwFileVersionMS);
  WORD minor = LOWORD(pFileInfo->dwFileVersionMS);
  WORD build = HIWORD(pFileInfo->dwFileVersionLS);

  ATLTRACE2(L"StickyTweets version %d.%d.%d\n", major, minor, build);
  delete pVersionInfo;
}
#endif